package top.lyc829.mymusic.ui.fragment.play_list_ground

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.chad.library.adapter.base.BaseBinderAdapter
import top.lyc829.mymusic.adapter.IndexRecommendPlayListAdapter
import top.lyc829.mymusic.base.BaseViewModel
import top.lyc829.mymusic.model.bean.PageInfo
import top.lyc829.mymusic.model.bean.PlayListSimple
import top.lyc829.mymusic.model.http.MyNetwork
import top.lyc829.mymusic.model.repository.PlayListRepository

/**
 * @Author lyc
 * @create 2021-08-30 11:06
 */
class PlayListGroundViewModel: BaseViewModel() {

    private var playListRepository: PlayListRepository =
        PlayListRepository.getInstance(MyNetwork.getInstance())

    // 可以直接快速使用，也可以继承BaseBinderAdapter类，重写自己的相关方法
//    private val adapter = BaseBinderAdapter()
    val adapter = IndexRecommendPlayListAdapter()

    val pageInfo: PageInfo = PageInfo()

    private val _playList: MutableLiveData<List<PlayListSimple>> by lazy { MutableLiveData() }
    val playList: LiveData<List<PlayListSimple>> get() = _playList


    fun getPlayList() {
        launch(true,
            {
                val playList = playListRepository.getTopPlayList(offset = pageInfo.page * 20, limit = 20)
                _playList.value = playList
                pageInfo.page++
            }, {
                errorLiveData.value = it
            })
    }


}